package com.microcore.protolbuffer;

import lombok.val;
import org.platform.mo.bussmo.task.TaskExecutorStep;
import org.platform.mo.bussmo.task.TaskReport;
import org.zeromq.ZMQ;

/**
 * @author FengJie
 * @date 2018/7/12
 */
public class Server {

    public static void main(String[] args) {
        ZMQ.Context context = ZMQ.context(1);
        ZMQ.Socket socket = context.socket(ZMQ.PUB);
        socket.bind("tcp://*:28881");

        final val processData = getProcessData();
        System.out.println(processData.toString());
        socket.sendMore("TaskSteps_TASK");
        socket.send(processData.toByteArray());
        socket.close();
        context.close();
    }

    //模拟任务上报信息
    private static TaskReport.TaskList getTaskList() {
        TaskReport.channelEqu channelEqu = TaskReport.channelEqu.newBuilder()
                .setDas("test")
                .setDecodeMode("test")
                .setDemodMode("test")
                .setBitRate(11)
                .setChlIndex(1)
                .setChlRecvPol(1)
                .setDC("DCDCDCDCDC")
                .build();

        TaskReport.WorkSchInfo wordSchInfo = TaskReport.WorkSchInfo.newBuilder()
                .setTaskSerialNumber("taskID")
                .setJobTaskID("jobID")
                .setAntennaID("AntennaID")
                .setCreator("test")
                .setJobTaskID("test")
                .setOrbitNumber("test")
                .setSatelliteName("test")
                .setAzIn(22)
                .addChannelinfo(channelEqu)
                .build();

        TaskReport.TaskList taskList = TaskReport.TaskList.newBuilder()
                .setStationID("StationID")
                .setSchCount(3333)
                .setSchInfo(wordSchInfo)
                .build();

        return taskList;
    }

    //模拟任务执行步骤
    private static TaskExecutorStep.TaskProcessData getProcessData() {
        TaskExecutorStep.StepInfo stepInfo1 = TaskExecutorStep.StepInfo.newBuilder()
                .setStepName("testValue")
                .setStepNo("testValue")
                .setStepStatus("testValue")
                .build();

        TaskExecutorStep.StepInfo stepInfo2 = TaskExecutorStep.StepInfo.newBuilder()
                .setStepName("testValue")
                .setStepNo("testValue")
                .setStepStatus("testValue")
                .build();

        TaskExecutorStep.TaskProcessData taskProcessData = TaskExecutorStep.TaskProcessData.newBuilder()
                .setJobTaskID("testValue")
                .setJobTaskID("testValue")
                .setAntennaID("testValue")
                .setAntennaName("testValue")
                .addSteps(stepInfo1)
                .addSteps(stepInfo2)
                .build();

        return taskProcessData;
    }
}
